package cn.wolfcode.mp.service.impl;

import cn.wolfcode.mp.domain.Employee;
import cn.wolfcode.mp.mapper.EmployeeMapper;
import cn.wolfcode.mp.query.EmployeeQuery;
import cn.wolfcode.mp.service.IEmployeeService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.List;

/**
 * 自定义通用服务层接口实现类写法：
 * 1>实现自定义服务接口IEmployeeService
 * 2>继承IServiceImpl 通用接口实现类
 * 3>明确指定2个泛型
 *      1:当前操作的实体对象对应的Mapper接口 EmployeeMapper
 *      2：当前操作的实体对象     Employee
 */
@Service
public class EmployeeServiceImpl extends ServiceImpl<EmployeeMapper, Employee> implements IEmployeeService {

    /*@Autowired
    private EmployeeMapper employeeMapper;*/

    @Override
    public Page<Employee> queryPage(EmployeeQuery qo) {

        //分页操作
        Page<Employee> page = new Page<>(qo.getCurrentPage(),qo.getPageSize());

        QueryWrapper<Employee> wrapper = new QueryWrapper<>();

        //根据StringUtils.hasLength 方法 判断Keyword 是否有值
        //有值，进行拼接到SQL语句中
        wrapper.like(StringUtils.hasLength(qo.getKeyword()),"name",qo.getKeyword());

        //1.employeeMapper.selectPage(page,wrapper);

        //2.从父接口中获取 employeeMapper对象
        //super.getBaseMapper().selectPage(page,wrapper);

        //3.从父接口中直接获取分页方法
        return  super.page(page,wrapper);
    }
}
